package com.springboot.demo.service;

import com.springboot.demo.dao.BookDao;
import com.springboot.demo.dao.UserInfoDao;
import com.springboot.demo.entity.Book;
import com.springboot.demo.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookService{

    @Autowired
    private BookDao bookDao;

    public Book findBookByName(String name){
        return bookDao.findByName(name);
    }

    public List<Book> findAll(){
        return bookDao.findAll();
    }

    public Book saveBook(Book book){
        return  bookDao.save(book);
    }

    public Book findBookById(long id){
        return bookDao.findById(id).get();
    }
    public Book updateBook(Book book){
        return bookDao.saveAndFlush(book);
    }
    public void deleteBook(long id){
        bookDao.deleteById(id);
    }
}
